package com.zjljr.order.controller;

import com.zjljr.order.feign.StockServiceFeign;
import com.zjljr.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RefreshScope
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    RestTemplate restTemplate;
    @Autowired
    StockServiceFeign stockServiceFeign;

    @RequestMapping("/add")
    public String add() {
        System.out.println("插入订单");
        //String msg = restTemplate.getForObject("http://localhost:8011/stock/reduce", String.class);
        //负载均衡@LoadBalanced-RestTemplate + nacos服务发现
        //String msg = restTemplate.getForObject("http://stock-server/stock/reduce", String.class);
        //openFeign使用
        String msg = stockServiceFeign.reduce();
        return "订单添加成功--"+msg;
    }

    @Value("${author}")
    String author;
    @RequestMapping("/author")
    public String author() {
        return author;
    }


    @RequestMapping("/sentinel")
    public String sentinel() {
        return "测试sentinel";
    }


    @Autowired
    private OrderService orderService;

    @RequestMapping("/addOrder")
    public String addOrder(@RequestParam("productId") Integer productId) {
        orderService.addOrder(productId);
        return "添加订单成功";
    }

}
